package cn.iocoder.yudao.module.member.assets.service;

import cn.iocoder.yudao.framework.business.basic.dao.query.CoreQueryWrapper;
import cn.iocoder.yudao.framework.business.basic.pojo.vo.UserSimpleVO;
import cn.iocoder.yudao.framework.business.basic.service.impl.MemberScopeService;
import cn.iocoder.yudao.module.api.member.user.MemberUserApi;
import cn.iocoder.yudao.module.member.assets.convert.CryptocurrencyIncreasingTaskConvert;
import cn.iocoder.yudao.module.member.assets.dal.dataobject.CryptocurrencyIncreasingTaskDO;
import cn.iocoder.yudao.module.member.assets.dal.mysql.CryptocurrencyIncreasingTaskMapper;
import cn.iocoder.yudao.module.member.assets.vo.AdminCryptocurrencyIncreasingTaskQueryDTO;
import cn.iocoder.yudao.module.member.assets.vo.AdminCryptocurrencyIncreasingTaskVO;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.Collection;
import java.util.Map;

/**
 * 联盟豆增值任务 Service 实现类
 *
 * @author 山野羡民
 */
@Slf4j
@Service
@Validated
public class AdminCryptocurrencyIncreasingTaskServiceImpl extends MemberScopeService<CryptocurrencyIncreasingTaskDO, AdminCryptocurrencyIncreasingTaskVO, AdminCryptocurrencyIncreasingTaskQueryDTO> implements AdminCryptocurrencyIncreasingTaskService {
    @Resource
    private CryptocurrencyIncreasingTaskMapper cryptocurrencyIncreasingTaskMapper;

    @Resource
    private MemberUserApi memberUserApi;

    @Override
    protected CryptocurrencyIncreasingTaskMapper getInjectedMapper() {
        return cryptocurrencyIncreasingTaskMapper;
    }

    @Nonnull
    @Override
    protected CoreQueryWrapper<CryptocurrencyIncreasingTaskDO> buildQueryWrapper(AdminCryptocurrencyIncreasingTaskQueryDTO param) {
        CoreQueryWrapper<CryptocurrencyIncreasingTaskDO> wrapper = super.buildQueryWrapper(param);
        wrapper.eqIfPresent("status", param.getStatus());
        wrapper.eqIfPresent("user_id", param.getUserId());
        wrapper.orderByDesc("update_time");
        return wrapper;
    }

    @Nonnull
    @Override
    protected Map<Long, UserSimpleVO> getUserSimpleMap(Collection<Long> userIds) {
        return memberUserApi.getUserSimpleMap(userIds);
    }

    @Override
    public AdminCryptocurrencyIncreasingTaskVO convertToViewObject(CryptocurrencyIncreasingTaskDO entity) {
        return CryptocurrencyIncreasingTaskConvert.INSTANCE.convert(entity);
    }

}